package org.muxiao.seckill.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import static org.muxiao.seckill.config.RabbitMQSecKillConfig.EXCHANGE_SECKILL;

/**
 * MQSenderMessage: 消息的生产者/发送者[秒杀消息]
 */
@Service
@Slf4j
public class MQSenderMessage {

    /**
     * 注入RabbitTemplate对象
     */
    @Resource
    private RabbitTemplate rabbitTemplate;


    /**
     * 发送秒杀消息
     *
     * @param message
     */
    public void sendSecKillMessage(String message) {
        log.info("发送消息-->" + message);
        rabbitTemplate.convertAndSend(EXCHANGE_SECKILL, "seckill.message", message);
    }
}
